local qubi = fk.CreateSkill {
  name = "lingling__qubi",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable{
  ["lingling__qubi"] = "趋避",
  [":lingling__qubi"] = "锁定技，回合开始时，你令一名其他角色本回合不能使用或打出【闪】以外的牌，且装备区所有牌无效。"..
  "本回合前两次有【闪】进入弃牌堆后，你摸两张牌。",

  ["#lingling__qubi-choose"] = "趋避：令一名角色本回合不能使用或打出非【闪】牌且装备无效！",
  ["@@lingling__qubi-turn"] = "趋避",
}

qubi:addEffect(fk.TurnStart, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(qubi.name) and
      #player.room:getOtherPlayers(player, false) > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:askToChoosePlayers(player, {
      targets = room:getOtherPlayers(player, false),
      min_num = 1,
      max_num = 1,
      prompt = "#lingling__qubi-choose",
      skill_name = qubi.name,
      cancelable = false,
    })[1]
    room:setPlayerMark(to, "@@lingling__qubi-turn", 1)
  end,
})

qubi:addEffect(fk.AfterCardsMove, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(qubi.name) and player.room.current == player and
      player:usedEffectTimes(qubi.name, Player.HistoryTurn) < 2 then
      for _, move in ipairs(data) do
        if move.toArea == Card.DiscardPile then
          for _, info in ipairs(move.moveInfo) do
            if Fk:getCardById(info.cardId).trueName == "jink" then
              return true
            end
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(2, qubi.name)
  end,
})

qubi:addEffect("prohibit", {
  prohibit_use = function (self, player, card)
    return player:getMark("@@lingling__qubi-turn") > 0 and card and card.trueName ~= "jink"
  end,
  prohibit_response = function (self, player, card)
    return player:getMark("@@lingling__qubi-turn") > 0 and card and card.trueName ~= "jink"
  end,
})

qubi:addEffect("invalidity", {
  invalidity_func = function(self, from, skill)
    if from:getMark("@@lingling__qubi-turn") > 0 and skill:isEquipmentSkill(from) then
      return true
    end
  end,
  invalidity_attackrange = function (self, player, card)
    if player:getMark("@@lingling__qubi-turn") > 0 then
      return table.contains(player:getEquipments(Card.SubtypeWeapon), card:getEffectiveId())
    end
  end,
})

return qubi
